package com.fduss.mazegame;

import com.fduss.mazegame.client.ClientChoice;
import com.fduss.mazegame.client.gui.fxgui.CorGui;
import com.fduss.mazegame.client.gui.fxgui.TEXGui;
import com.fduss.mazegame.client.tui.StoryTui;
import com.fduss.mazegame.client.tui.Tui;

public class Main {

    public static void main(String args[]) {
        CLOptions opts = null;
        try {
            opts = CLOptions.getInstance(args);
        } catch (IllegalArgumentException e) {
            System.err.println(e.getMessage());
            usage();
            System.exit(1);
        }
        ClientChoice clientChoice = opts.getClientChoice();
        switch (clientChoice) {
            case TUI:
                new Tui(opts).run();
                return;
            case STORYTUI:
                new StoryTui(opts).run();
                return;
            case CORGUI:
                CorGui.main(args);
                return;
            case TEXGUI:
                TEXGui.main(args);
                return;
            default:
                throw new UnsupportedOperationException("Unsupported client choice: " + clientChoice.toString());
        }
    }

    private static void usage() {
        System.err.println("options:");
        System.err.println(
                "\t-l (ENGLISH|CHINESE)" + System.lineSeparator() +
                        "\t\tsets the language for the user interface");
        System.err.println();
        System.err.println(
                "\t-s (TEST|EMPTY|PRIM|DEPTHFIRST)" + System.lineSeparator() +
                        "\t\t Map generation style");
        System.err.println();
        System.err.println(
                "\t-r number" + System.lineSeparator() +
                        "\t\t number of rows in the maze (ignored if using the TEST maze)");
        System.err.println();
        System.err.println(
                "\t-c number" + System.lineSeparator() +
                        "\t\t number of columns in the maze (ignored if using the TEST maze)");
        System.err.println();
        System.err.println(
                "\t-ui (TUI|CORGUI|TEXGUI)" + System.lineSeparator() +
                        "\t\t choose between a textual client, a javafx" +
                        " color-based graphical one, a javafx texture based graphical one.");
        System.err.println();
        System.err.println(
                "\t-th (snow|grass)" + System.lineSeparator() +
                        "\t\t choose a theme of maze."
        );
        System.err.println();
        System.err.println(
                "\t-tr num" + System.lineSeparator() +
                        "\t\t the length of footprints."
        );
        System.err.println();
        System.err.println(
                "\tdefaults: -l " + CLOptions.DEFAULT_LANGUAGE +
                        " -s DEPTHFIRST " +
                        " -r " + CLOptions.DEFAULT_ROWS +
                        " -c " + CLOptions.DEFAULT_COLS +
                        " -th " + CLOptions.DEFAULT_THEME.name() +
                        " -tr " + CLOptions.DEFAULT_TRAIL_CAPACITY +
                        " -ui " + CLOptions.DEFAULT_CLIENT_CHOICE);
    }
}
